package com.jeeplus.modules.guide.utils;

import com.jeeplus.modules.guide.web.MobileLoginController;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoRequest;
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CheckFace {
    //获取人脸认证信息
    private static final Logger log = LoggerFactory.getLogger(CheckFace.class);
    public static String getCheckFaceUrl(String SecretId, String SecretKey,String resultUrl) {
        try {
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"RedirectUrl\":\""+resultUrl+"\",\"RuleId\":\"1\"}";
            DetectAuthRequest req = DetectAuthRequest.fromJsonString(params, DetectAuthRequest.class);
            DetectAuthResponse resp = client.DetectAuth(req);
            return DetectAuthRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
            return null;
        }
    }

    //获取人脸认证url 后台传入IdCard，name
    public static String getNoCardNameUrl(String SecretId, String SecretKey,String resultUrl,String Name,String IdCard) {
        try {
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"IdCard\":\""+IdCard+"\",\"Name\":\""+Name+"\",\"RedirectUrl\":\""+resultUrl+"\",\"RuleId\":\"3\"}";
            DetectAuthRequest req = DetectAuthRequest.fromJsonString(params, DetectAuthRequest.class);
            DetectAuthResponse resp = client.DetectAuth(req);
            return DetectAuthRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
            return null;
        }
    }

    //查询人脸认证信息返回结果 前台传身份信息
    public static String GetDetectInfo(String SecretId, String SecretKey,String BizToken) {
        try{
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"BizToken\":\""+BizToken+"\",\"RuleId\":\"1\",\"InfoType\":\"12\"}";
            GetDetectInfoRequest req = GetDetectInfoRequest.fromJsonString(params, GetDetectInfoRequest.class);
            GetDetectInfoResponse resp = client.GetDetectInfo(req);
            return GetDetectInfoRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            log.error(e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    //查询人脸认证信息返回结果 前台传身份信息 获取基础信息
    public static String GetDetectOnlyInfo(String SecretId, String SecretKey,String BizToken) {
        try{
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"BizToken\":\""+BizToken+"\",\"RuleId\":\"1\",\"InfoType\":\"1\"}";
            GetDetectInfoRequest req = GetDetectInfoRequest.fromJsonString(params, GetDetectInfoRequest.class);
            GetDetectInfoResponse resp = client.GetDetectInfo(req);
            return GetDetectInfoRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            return null;
        }
    }

    //查询人脸认证信息返回结果 后台传身份信息
    public static String GetDetectInfoText(String SecretId, String SecretKey,String BizToken) {
        try{
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"BizToken\":\""+BizToken+"\",\"RuleId\":\"3\",\"InfoType\":\"1\"}";
            GetDetectInfoRequest req = GetDetectInfoRequest.fromJsonString(params, GetDetectInfoRequest.class);
            GetDetectInfoResponse resp = client.GetDetectInfo(req);
            return GetDetectInfoRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            return null;
        }
    }

    //查询人脸认证信息返回结果 后台传身份信息 全量信息
    public static String GetDetectInfoTextAll(String SecretId, String SecretKey,String BizToken) {
        try{
            Credential cred = new Credential(SecretId, SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            FaceidClient client = new FaceidClient(cred, "ap-chengdu", clientProfile);
            String params = "{\"BizToken\":\""+BizToken+"\",\"RuleId\":\"3\",\"InfoType\":\"12\"}";
            GetDetectInfoRequest req = GetDetectInfoRequest.fromJsonString(params, GetDetectInfoRequest.class);
            GetDetectInfoResponse resp = client.GetDetectInfo(req);
            return GetDetectInfoRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            return null;
        }
    }
}
